home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
awe2-0_1.lha
/
awe2-0.1
/
Src
/
RCS
/
ThreadEventPairingHeap.h,v
< prev
next >
Wrap
Text File
|
1988-10-12
|
6KB
|
237 lines
head 1.1;
access ;
symbols ;
locks grunwald:1.1; strict;
comment @ * @;
1.1
date 88.10.12.10.51.13; author grunwald; state Exp;
branches ;
next ;
desc
@@
1.1
log
@Initial revision
@
text
@// This may look like C code, but it is really -*- C++ -*-
/*
Copyright (C) 1988 Free Software Foundation
written by Dirk Grunwald (grunwald@@cs.uiuc.edu)
adapted for libg++ by Doug Lea (dl@@rocky.oswego.edu)
This file is part of GNU CC.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. No author or distributor
accepts responsibility to anyone for the consequences of using it
or for whether it serves any particular purpose or works at all,
unless he says so in writing. Refer to the GNU CC General Public
License for full details.
Everyone is granted permission to copy, modify and redistribute
GNU CC, but only under the conditions described in the
GNU CC General Public License. A copy of this license is
supposed to have been given to you along with GNU CC so you
can know your rights and responsibilities. It should be in a
file named COPYING. Among other things, the copyright notice
and this notice must be preserved on all copies.
*/
#ifndef ThreadEventPairingHeap_h
#define ThreadEventPairingHeap_h 1
#include "ThreadEvent.h"
#ifndef ThreadEventPairingHeapIndex
#define ThreadEventPairingHeapIndex unsigned short
#endif
#ifndef ThreadEventPairingHeapIndex_NULL
#define ThreadEventPairingHeapIndex_NULL 0xffff
#endif
#ifndef _ThreadEvent_typedefs
#define _ThreadEvent_typedefs 1
typedef void (*ThreadEventProcedure)(ThreadEvent );
typedef ThreadEvent (*ThreadEventMapper)(ThreadEvent );
typedef ThreadEvent (*ThreadEventCombiner)(ThreadEvent , ThreadEvent );
typedef int (*ThreadEventPredicate)(ThreadEvent );
typedef int (*ThreadEventComparator)(ThreadEvent , ThreadEvent );
#endif
struct ThreadEventPairingHeapRecord
{
ThreadEventPairingHeapIndex sibling;
ThreadEventPairingHeapIndex children;
ThreadEvent item;
char valid;
};
class ThreadEventPairingHeapTrav;
class ThreadEventPairingHeap
{
friend class ThreadEventPairingHeapTrav;
ThreadEventPairingHeapRecord* storage;
int elements;
ThreadEventPairingHeapIndex allocatedSize;
ThreadEventPairingHeapIndex freelist;
ThreadEventPairingHeapIndex root;
void make_room(int atLeast);
ThreadEventPairingHeapIndex get_cell();
void return_cell(ThreadEventPairingHeapIndex cell);
ThreadEventPairingHeapIndex make_child(ThreadEventPairingHeapIndex a,
ThreadEventPairingHeapIndex b);
public:
ThreadEventPairingHeap(int initial_cap = 0);
~ThreadEventPairingHeap();
ThreadEventPairingHeapIndex enq(ThreadEvent item);
ThreadEvent deq();
int deq(ThreadEvent& removed);
ThreadEvent& front();
int del_front();
ThreadEvent& item(ThreadEventPairingHeapIndex ind);
int valid(ThreadEventPairingHeapIndex ind);
int del(ThreadEventPairingHeapIndex ind);
ThreadEventPairingHeapIndex front_index();
int empty();
int length();
void error(const char* msg);
};
class ThreadEventPairingHeapTrav
{
ThreadEventPairingHeap* h;
ThreadEventPairingHeapIndex current;
public:
ThreadEventPairingHeapTrav(ThreadEventPairingHeap& heap);
~ThreadEventPairingHeapTrav();
int null();
int operator ! ();
const void* operator void* ();
ThreadEvent& get();
void advance();
void reset();
void reset(ThreadEventPairingHeap& heap);
void del();
ThreadEventPairingHeapIndex current_index();
};
inline ThreadEventPairingHeap::~ThreadEventPairingHeap()
{
delete [allocatedSize] storage;
}
inline ThreadEventPairingHeapIndex ThreadEventPairingHeap::front_index()
{
return root;
}
inline int ThreadEventPairingHeap::valid(ThreadEventPairingHeapIndex index)
{
return storage[index].valid;
}
inline ThreadEvent& ThreadEventPairingHeap::item(ThreadEventPairingHeapIndex i)
{
return storage[i].item;
}
inline int ThreadEventPairingHeap::empty()
{
return (elements <= 0);
}
inline int ThreadEventPairingHeap::length()
{
return elements;
}
inline ThreadEvent ThreadEventPairingHeap::deq()
{
if (root == ThreadEventPairingHeapIndex_NULL || elements <= 0)
error("attempted deq of empty heap");
ThreadEvent x = storage[root].item;
del_front();
return x;
}
inline int ThreadEventPairingHeap::deq(ThreadEvent& x)
{
if (root == ThreadEventPairingHeapIndex_NULL || elements <= 0)
return 0;
else
{
x = storage[root].item;
del_front();
return 1;
}
}
inline ThreadEvent& ThreadEventPairingHeap::front()
{
if (root == ThreadEventPairingHeapIndex_NULL || elements <= 0)
error("attempted front of empty heap");
return storage[root].item;
}
inline ThreadEventPairingHeapTrav::~ThreadEventPairingHeapTrav() {}
inline int ThreadEventPairingHeapTrav::null()
{
return current == ThreadEventPairingHeapIndex_NULL;
}
inline int ThreadEventPairingHeapTrav::operator !()
{
return current == ThreadEventPairingHeapIndex_NULL;
}
inline const void* ThreadEventPairingHeapTrav::operator void*()
{
return (current == ThreadEventPairingHeapIndex_NULL)? 0 : this;
}
inline ThreadEventPairingHeapIndex ThreadEventPairingHeapTrav::current_index()
{
return current;
}
inline ThreadEvent& ThreadEventPairingHeapTrav::get()
{
if (current == ThreadEventPairingHeapIndex_NULL)
h->error("get of null traverser");
return h->storage[current].item;
}
extern void default_ThreadEventPairingHeap_error_handler(char*);
extern one_arg_error_handler_t ThreadEventPairingHeap_error_handler;
extern one_arg_error_handler_t
set_ThreadEventPairingHeap_error_handler(one_arg_error_handler_t f);
#endif
@